<template>
  <div class="main">
    <div class="header-card">
      <div class="uc-header">
        <div class="back" @click="$router.back()">
          <img src="@/assets/img/3.png" />
        </div>
        <div class="popup-">{{ $t("Agen") }}</div>
      </div>
    </div>
    <div class="list"></div>
    <div class="content">
      <div class="content-box">
        <div class="content-box-text">
          {{ $t("AKun") }}: {{ agentInfo.account_name }}
        </div>
        <div class="content-box-text">
          {{ $t("SaldoTotal") }}: {{ agentInfo.total_amount }}
        </div>
        <div class="content-box-text">
          {{ $t("TingkatCashback") }}: {{ agentInfo.rebate_ratio }}
        </div>
      </div>
      <div class="content-text">
        <div>
          {{ $t("KodeUndangan") }}:
          <span class="invite_code">{{ agentInfo.invite_code }}</span>
          <span @click="handleCopy('Kode Undangan')"
            ><img class="copy" src="../../assets/img/copy.png"
          /></span>
        </div>
      </div>
      <div class="content-text">
        <div>
          {{ $t("TautanUndangan") }}:
          <span class="invite_url">{{ agentInfo.invite_url }}</span>
          <span @click="handleCopy('Tautan Undangan')"
            ><img class="copy" src="../../assets/img/copy.png"
          /></span>
        </div>
      </div>
      <div class="list"></div>
      <div class="content-text mb-20px">
        <div>{{ $t("PenggunaSaya") }}</div>
        <div @click="handleDetail('/Agen-Pengguna')">{{ $t("Rincian") }} ></div>
      </div>
      <div class="content-box">
        <div class="content-box-text">
          <div>{{ $t("Nomor") }}</div>
          <div>{{ inviteInfo.total_user }}</div>
        </div>
        <div class="content-box-text">
          <div>{{ $t("KomisiPerOrang") }}</div>
          <div>{{ inviteInfo.per_amount }}</div>
        </div>
        <div class="content-box-text">
          <div>{{ $t("PendapatanTotal") }}</div>
          <div>{{ inviteInfo.total_income }}</div>
        </div>
      </div>
      <div class="content-text mb-20px">
        <div>{{ $t("CashbackIsiUlang") }}</div>
        <div @click="handleDetail('/Agen-Cashback')">{{ $t("Rincian") }} ></div>
      </div>
      <div class="content-box">
        <div class="content-box-text">
          <div>{{ $t("BatasUlangTersedia") }}</div>
          <div>{{ rechargeInfo.total_quota }}</div>
        </div>
        <div class="content-box-text">
          <div>{{ $t("TotalUlang") }}</div>
          <div>{{ rechargeInfo.total_used }}</div>
        </div>
        <div class="content-box-text">
          <div>{{ $t("TotalCashback") }}</div>
          <div>{{ rechargeInfo.total_rebate }}</div>
        </div>
      </div>

      <div class="ulang">
        <div @click="handleUlang">{{ $t("lsiUlang") }}</div>
      </div>
    </div>
  </div>
</template>
<script>
import { Toast } from "vant";
import { httpAgentHome } from "@/http/api";
import { computed } from "vue";
export default {
  name: "ucenter",
  data() {
    return {
      feedBackMsg: "",
      feedBackFlag: false,
      background: localStorage.getItem("bgck"),
      avatar: localStorage.getItem("avatar"),
      // 代理信息
      agentInfo: {},
      // 邀请信息
      inviteInfo: {},
      // 充值信息
      rechargeInfo: {},
    };
  },

  mounted() {
    this.getAgentHome();
  },
  methods: {
    // 获取代理返利信息
    async getAgentHome() {
      let res = await httpAgentHome();
      console.log(res);
      if (res.code == 0) {
        this.agentInfo = res.data.info;
        this.inviteInfo = res.data.invitation;
        this.rechargeInfo = res.data.recharge;
      }
    },

    handleCopy(title) {
      const text = computed(() => {
        return title == "Kode Undangan"
          ? document.querySelector(".invite_code")
          : document.querySelector(".invite_url");
      });
      let range = document.createRange();
      range.selectNodeContents(text.value);
      let selection = document.getSelection();
      selection.removeAllRanges();
      selection.addRange(range);
      document.execCommand("Copy");
      Toast(title + this.$t("berhasilDisalin"));
    },
    handleAgen() {
      this.$router.push("/agent");
    },
    handleDetail(router) {
      this.$router.push(router);
    },
    handleUlang() {
      this.$router.push("/Agen-lsi");
    },
  },
};
</script>
<style lang="less" scoped>
@import url("./ucenter-common.less");

* {
  font-weight: 400;
  color: white;
}
.uc-header .back {
  height: initial;
}
.header-card {
  padding-bottom: 20px;
}
.list {
  margin-top: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid #fff;
}
.content {
  margin: 20px 0;
  &-box {
    margin: 0 20px 20px;
    padding: 20px;
    background: rgb(255, 243, 226);
    border-radius: 20px;
    &-text {
      line-height: 1.6;
      color: rgb(200, 108, 95);
      display: flex;
      justify-content: space-between;
      > div {
        color: rgb(200, 108, 95);
      }
    }
  }
  &-text {
    display: flex;
    justify-content: space-between;
    margin: 0 20px;
    line-height: 1.6;
    color: #fff;
  }
}
.mb-20px {
  margin-bottom: 20px;
}
.ulang {
  bottom: 5%;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  position: absolute;
  > div {
    width: 80vw;
    height: 80px;
    background: rgb(148, 195, 98);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    color: #fff;
  }
}
.copy {
  width: 40px;
  height: 40px;
  margin-left: 10px;
  display: inline-block;
}
</style>
